package com.linhui.project.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.gson.Gson;
import com.linhui.project.annotation.AuthCheck;
import com.linhui.project.common.BaseResponse;
import com.linhui.project.common.DeleteRequest;
import com.linhui.project.common.ErrorCode;
import com.linhui.project.common.ResultUtils;
import com.linhui.project.constant.UserConstant;
import com.linhui.project.exception.BusinessException;
import com.linhui.project.exception.ThrowUtils;
import com.linhui.project.model.dto.picture.PictureQueryRequest;
import com.linhui.project.model.dto.post.PostAddRequest;
import com.linhui.project.model.dto.post.PostEditRequest;
import com.linhui.project.model.dto.post.PostQueryRequest;
import com.linhui.project.model.dto.post.PostUpdateRequest;
import com.linhui.project.model.entity.Picture;
import com.linhui.project.model.entity.Post;
import com.linhui.project.model.entity.User;
import com.linhui.project.model.vo.PostVO;
import com.linhui.project.service.PictureService;
import com.linhui.project.service.PostService;
import com.linhui.project.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.swing.*;
import java.util.List;

/**
 * 帖子接口
 *
 * @author: 临晖
 * @since: 2024-05-18
 */
@RestController
@RequestMapping("/picture")
@Slf4j
public class PictureController {

    @Resource
    private PictureService pictureService;

    @Resource
    private UserService userService;

    private final static Gson GSON = new Gson();


    /**
     * 分页获取列表（封装类）
     *
     * @param pictureQueryRequest
     * @param request
     * @return
     */
    @PostMapping("/list/page/vo")
    public BaseResponse<Page<Picture>> listPictureVOByPage(@RequestBody PictureQueryRequest pictureQueryRequest,
                                                           HttpServletRequest request) {

        //搜索内容为空，默认搜索内容为“最新”
        if (StrUtil.isBlank(pictureQueryRequest.getSearchText())) {
            pictureQueryRequest.setSearchText("最新");
        }

        //当前页码错误
        if (pictureQueryRequest.getCurrent() <= 0) {
            pictureQueryRequest.setCurrent(1);
        }

        //当前页大小
        if (pictureQueryRequest.getPageSize() <= 0) {
            pictureQueryRequest.setPageSize(8);
        }
        //获取图片集合
        Page<Picture> pictures = pictureService.searchPicture(pictureQueryRequest.getSearchText(), pictureQueryRequest.getCurrent(),
                pictureQueryRequest.getPageSize());
        return ResultUtils.success(pictures);
    }


}
